package com.letchat.controller;

import com.letchat.utils.JwtUtils;
import com.letchat.pojo.Result;
import com.letchat.pojo.User;
import com.letchat.service.impl.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@CrossOrigin
public class LoginController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     *
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        log.info("用户名:{},密码:{}", user.getUsername(), user.getPassword());
        String token = userService.login(user);
        if (token != null) return Result.success(token);
        return Result.error("用户名或密码错误");
    }

    /**
     * 检测是否登录
     *
     * @return
     */
    @GetMapping("/isLogin")
    public Result isLogin() {
        return Result.success();
    }
}
